﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace SimpleTools
{
    public static class FileHelp
    {
        public static void SaveStringData(string filePath, string content)
        {
            if (!Directory.Exists(filePath.Substring(0, filePath.LastIndexOf('\\'))))
            {
                Directory.CreateDirectory(filePath.Substring(0, filePath.LastIndexOf('\\')));
            }
            if (!File.Exists(filePath))
            {
                FileStream fs = File.Create(filePath);

                fs.Flush(); fs.Close(); fs.Dispose();
            }
            StreamWriter sw = new StreamWriter(filePath);
            sw.Write(content);
            sw.Close();
        }

        public static string GetStringData(string filePath)
        {
            if (File.Exists(filePath))
            {
                string content = File.ReadAllText(filePath, Encoding.UTF8);
                return content;
            }
            return null;
        }
    }
}
